<?php

class sfGoogleAnalyticsFilter extends sfFilter
{
    public function execute($filterChain)
    {
        $c = new Criteria();
        $c->add(TblSettingPeer::F_PARAMETER, "google analytic");
        $tblSetting = TblSettingPeer::doSelectOne($c);

        // Nothing to do before the action
        $filterChain->execute();

        // Decorate the response with the tracker code
        $googleCode = "";
        if ($tblSetting)
            $googleCode = $tblSetting->getFValue();
        $response = $this->getContext()->getResponse();
        $response->setContent(str_ireplace('</body>', $googleCode . '</body>', $response->getContent()));
    }
}